﻿using Mt.Site.Core.WorkFlows.Design;
using Mt.Site.Core.WorkFlows.Enum;
using Mt.Site.Core.WorkFlows.Process.Entities;
using System;
using System.Threading.Tasks;

namespace Mt.Site.Core.WorkFlows.Process.Models
{
    internal class PaperContext : IPaperContext
    {
        private readonly Guid _paparId;

        public PaperContext(Guid paparId)
        {
            _paparId = paparId;
        }

        public async Task Initialize(IWorkFlowManager workFlowManager)
        {
            Paper = await workFlowManager.WorkFlowPaperRepository.GetAsync(_paparId);

            //读取当前过程
            WorkFlow = await workFlowManager.WorkFlowFactory.GetWorkflowDefinitionAsync(Paper.WorkFlowId);
            CurrentNode = WorkFlow.FindNode(Paper.NodeId);
        }

        public WorkFlowPaper Paper { get; private set; }

        public Guid WorkFlowId => WorkFlow.Definition.WorkFlowId;

        public Guid NodeId => CurrentNode.Definition.NodeId;

        public IWorkflowDefinition WorkFlow { get; private set; }

        public IWorkflowNodeDefinition CurrentNode { get; private set; }

        public string WorkFlowName => WorkFlow.Definition.Name;

        public string CurrentNodeName => CurrentNode.Definition.Name;

        public PaperState PaperState => Paper.PaperState;
    }
}
